import pytest
import requests
import api.test2.Utils as Utils
from api.test2.method.Method import *


class TestCard:
    @pytest.mark.parametrize("ages", Utils.read_yaml("../data/money.yml"))
    def test_changemoney(self, ages):
        data = ages["changemoney"]
        print(data)
        method = Method()
        session = requests.session()
        method.login(session, data.get("user", []))
        request = method.send_post(session, data.get("url", ""), data.get('data', {}))
        result = [request['code'], request['result']['code']]
        Utils.delete_card()
        assert result == data.get("expect", [])

    @pytest.mark.parametrize("ages", Utils.read_yaml("../data/money.yml"))
    def test_fundproduct(self, ages):
        data = ages["fundproduct"]
        print(data)
        method = Method()
        session = requests.session()
        method.login(session, data.get("user", []))
        url = data.get("url", "")
        request = method.send_post(session, url, data.get('data', {}))
        result = [request['code'], request['result']['code']]
        Utils.delete_card()
        assert result == data.get("expect", [])

    @pytest.mark.parametrize("ages", Utils.read_yaml("../data/money.yml"))
    def test_termfinancial(self, ages):
        data = ages["termfinancial"]
        print(data)
        method = Method()
        session = requests.session()
        method.login(session, data.get("user", []))
        url = data.get("url", "")
        request = method.send_post(session, url, data.get('data', {}))
        result = [request['code'], request['result']['code']]
        Utils.delete_card()
        assert result == data.get("expect", [])

